package com.sxbbc.plat.controller.banks;


import com.function.common.GetRest;
import com.sxbbc.bank.service.ISysPushTagsService;
import com.sxbbc.common.basics.rest.RestResponse;
import com.sxbbc.common.core.entity.banks.SysProduct;
import com.sxbbc.common.core.entity.banks.SysProductType;
import com.sxbbc.common.core.entity.banks.SysPushTags;
import com.sxbbc.common.core.utils.BasePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * <p>
 * 推送标签表 前端控制器
 * </p>
 *
 * @author
 * @since 2020-09-15
 */
@Controller
public class SysPushTagsController {

    @Autowired
    private ISysPushTagsService sysPushTagsService;

    @RequestMapping(value = "/sysPushTags/list")
    public ModelAndView listView() {
        ModelAndView view = new ModelAndView("/banks/sysPushTags/index");
        return view;
    }

    @RequestMapping(value = "/sysPushTags/sysPushTagsSave")
    public ModelAndView saveView(SysPushTags sysPushTags ){
        ModelAndView view = new ModelAndView("/banks/sysPushTags/sysPushTagsSave");
        view.addObject("sysPushTags",sysPushTags);
        return view;
    }

    @RequestMapping(value ="/sysPushTags/listData")
    @ResponseBody
    public RestResponse selectSysPushTagsList(BasePage<SysPushTags> page, SysPushTags sysPushTags, String yyTime) {
        return sysPushTagsService.selSysPushTags(page,sysPushTags,yyTime);
    }

    @RequestMapping(value = "/sysPushTags/save")
    @ResponseBody
    public com.function.common.RestResponse handleSaveSysPushTagsRepository(SysPushTags sysPushTags) {
        if ("".equals(sysPushTags.getTagsName()) && sysPushTags.getTagsName() == null){
            return GetRest.getFail("请输入标签名");
        }
        if ("".equals(sysPushTags.getTagsCode()) && sysPushTags.getTagsCode() == null){
            return GetRest.getFail("请输入标签编码");
        }
        if (sysPushTags.getStatus() == null){
            return GetRest.getFail("请输入状态");
        }
        sysPushTags.setCreateTime(new Date());
        if (sysPushTags.getId() == null){
            return sysPushTagsService.addSysPushTag(sysPushTags);
        }else {
            return sysPushTagsService.updateSysPushTag(sysPushTags);
        }
    }


    @RequestMapping(value = "/sysPushTags/deactivate")
    @ResponseBody
    public com.function.common.RestResponse deactivateProductType(Integer id){
        SysPushTags sysPushTags = sysPushTagsService.getById(id);
        if (sysPushTags != null){
            if (sysPushTags.getStatus() == 0){
                return GetRest.getFail("该标签型已停用");
            }
            sysPushTags.setStatus(0);
            boolean saved = sysPushTagsService.updateById(sysPushTags);
            if (!saved) {
                return GetRest.getFail("停用失败");
            }
            return GetRest.getSuccess("停用成功");
        }else {
            return GetRest.getFail("该标签不存在，请重新再试");
        }
    }

    @RequestMapping(value = "/sysPushTags/enable")
    @ResponseBody
    public com.function.common.RestResponse enableProductType(Integer id){
        SysPushTags sysPushTags = sysPushTagsService.getById(id);
        if (sysPushTags != null){
            if (sysPushTags.getStatus() == 1){
                return GetRest.getFail("该标签已启用");
            }
            sysPushTags.setStatus(1);
            boolean saved = sysPushTagsService.updateById(sysPushTags);
            if (!saved) {
                return GetRest.getFail("启用失败");
            }
            return GetRest.getSuccess("启用成功");
        }else {
            return GetRest.getFail("该标签不存在，请重新再试");
        }
    }

}
